package com.bawei.module_mine.common

import com.bawei.lib_net.datastore.DataStoreUtils
import com.bawei.module_mine.model.entity.UserEntity


/**
 * @author hahajing 企鹅：444511958
 * @createDate 2022/8/11 8:40
 * @description
 *
 * @updateUser hahajing
 * @updateDate 2022/8/11 8:40
 * @updateRemark
 *
 * @version 1.0.0
 */
object UserUtils {
    /**
     * 判断用户是否登录
     */
    fun isLogin():Boolean{
        val user = DataStoreUtils.getData(ConstanstValue.CURRENT_USER,"")
        if(!user.isBlank()){
            return true
        }
        return false
    }

    /**
     * 获取当前登录用户
     */
    fun getCurrentUser(): UserEntity?{
        val user = DataStoreUtils.getData(ConstanstValue.CURRENT_USER,"")
        if (!user.isBlank()){
            val currentUser=GsonUtil.fromJson<UserEntity>(user,UserEntity::class.java)
            return currentUser
        }
        return null
    }

    /**
     * 获取登录用户Json数据
     */
    fun getCurrentUserJson():String{
        val user = DataStoreUtils.getData(ConstanstValue.CURRENT_USER,"")
        if (!user.isBlank()){
            return user
        }
        return ""
    }
}